package com.s7.pull.api;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.s7.pull.listener.OnAnimEndListener;

/**
 * Internal 初步实现
 * 实现 Header 和 Footer 时，继承 InternalAbstract 的话可以少写很多接口方法
 */
public class InternalAbstract extends RelativeLayout implements RefreshInternal {

    protected View mWrappedView;
    protected RefreshInternal mWrappedInternal;

    protected InternalAbstract(@NonNull View wrapped) {
        this(wrapped, wrapped instanceof RefreshInternal ? (RefreshInternal) wrapped : null);
    }

    protected InternalAbstract(@NonNull View wrappedView, @Nullable RefreshInternal wrappedInternal) {
        super(wrappedView.getContext(), null, 0);
        this.mWrappedView = wrappedView;
        this.mWrappedInternal = wrappedInternal;
    }

    protected InternalAbstract(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean equals(Object obj) {
        if (!super.equals(obj)) {
            if (obj instanceof RefreshInternal) {
                final RefreshInternal thisView = this;
                return thisView.getView() == ((RefreshInternal)obj).getView();
            }
            return false;
        }
        return true;
    }

    @NonNull
    @Override
    public View getView() {
        return mWrappedView == null ? this : mWrappedView;
    }

    @Override
    public void onPull(float fraction, float maxDragHeight, float height) {

    }

    @Override
    public void onPullReleasing(float fraction, float maxDragHeight, float height) {

    }

    @Override
    public void startAnim(float maxHeight, float height) {

    }

    @Override
    public void onFinish(OnAnimEndListener listener) {

    }

    @Override
    public void reset() {

    }
}
